package com.example.safe.keyboard;

import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import com.example.safe.keyboard.databinding.ActivityMainBinding;
import com.surfin.safe.keyboard.IKeyboardListener;
import com.surfin.safe.keyboard.KeyboardManager;
import com.surfin.safe.keyboard.SafeKeyboard;
import com.surfin.safe.keyboard.SafeKeyboardConfig;

public class MainActivity extends AppCompatActivity {

    private SafeKeyboard safeKeyboard;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        // 配置软键盘
        SafeKeyboardConfig config = SafeKeyboardConfig.getDefaultConfig();
        config.keyboardTitle = "安全键盘";
        safeKeyboard = new SafeKeyboard(this, binding.llKeyboardContainer,
                binding.ctlRoot, config);
        // 普通键盘
        safeKeyboard.putEditText(binding.safeEditText);
        // 随机键盘
        safeKeyboard.putRandomEdit(binding.numberEditText);
        binding.btnLetterNumber.setOnClickListener(v -> com.example.safe.keyboard.LetterNumberActivity.start(MainActivity.this));
        binding.btnScrollviewTest.setOnClickListener(v -> ScrollTestActivity.start(MainActivity.this));
        binding.btnPopupWindowTest.setOnClickListener(v -> com.example.safe.keyboard.PopupWindowTestActivity.start(MainActivity.this));
        binding.btnDialogTest.setOnClickListener(v -> com.example.safe.keyboard.DialogTestActivity.start(MainActivity.this));
        binding.btnCryptTest.setOnClickListener(v -> com.example.safe.keyboard.CryptTestActivity.start(MainActivity.this));
        // 初始化
        KeyboardManager.getInstance().init(this);
        KeyboardManager.getInstance().addListener(new IKeyboardListener() {
            @Override
            public void onTextChange(String editTextId, CharSequence str) {
                // editText内容改变
            }

            @Override
            public void onShow() {
                // 键盘出现
            }

            @Override
            public void onHide() {
                // 键盘隐藏
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (safeKeyboard != null) {
            safeKeyboard.release();
            safeKeyboard = null;
        }
    }
}